import pymysql
class DB:
    def __init__(self):
        self.conn = pymysql.connect(host="localhost",user="root",password="213416",
        port=3306,db="p9ks",charset="utf8",cursorclass=pymysql.cursors.DictCursor)
        self.cursor = self.conn.cursor()

    def find(self,sql):
        self.cursor.execute(sql)
        return self.cursor.fetchone()

    def find_all(self,sql):
        self.cursor.execute(sql)
        return self.cursor.fetchall()

    def update(self,sql):
        self.cursor.execute(sql)
        self.conn.commit()

    def close(self):
        self.cursor.close()
        self.conn.close()

db1 = DB()

import datetime
# stime = int((datetime.datetime.now()-datetime.timedelta(days=7)).timestamp())
# etime = int(datetime.datetime.now().timestamp())
# starttime = datetime.datetime.strptime(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),"%Y-%m-%d %H:%M:%S")-datetime.timedelta(days=7)
# endtime = datetime.datetime.strptime(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),"%Y-%m-%d %H:%M:%S")
# sql = "select from_unixtime(stime) from scores where user_id=1 and from_unixtime(stime) between '2021-12-29' and '2022-01-05' group by from_unixtime(stime)"
# data = db1.find_all(sql)
# print(stime)
# print(etime)
# print(data)




# stime = datetime.datetime.strftime((datetime.datetime.now()-datetime.timedelta(days=7)),"%Y-%m-%d")
# etime = datetime.datetime.strftime(datetime.datetime.now(),"%Y-%m-%d")
# id = 1
# sql = "select from_unixtime(stime,'%%Y-%%m-%%d') as stime,group_concat(tscore) as tscore from scores where user_id=%d  and from_unixtime(stime,'%%Y-%%m-%%d') between '%s' and '%s' group by from_unixtime(stime,'%%Y-%%m-%%d') order by from_unixtime(stime,'%%Y-%%m-%%d')"%(int(id),stime,etime)
# data = db1.find_all(sql)
# tlst = []
# dlst = []
# for i in data:
#     tlst.append(i["stime"])
#     dlst.append(i["tscore"].split(",")[-1])
# print(tlst)
# print(dlst)
# print(data)
# print(stime)
# print(etime)

# import datetime
# print(int((datetime.datetime.now()-datetime.timedelta(days=7)).timestamp()))
# print(int((datetime.datetime.now()-datetime.timedelta(days=6)).timestamp()))
# print(int((datetime.datetime.now()-datetime.timedelta(days=5)).timestamp()))
# print(int((datetime.datetime.now()-datetime.timedelta(days=4)).timestamp()))
# print(int((datetime.datetime.now()-datetime.timedelta(days=3)).timestamp()))
# print(int((datetime.datetime.now()+datetime.timedelta(days=1)).timestamp()))
# print(int(datetime.datetime.now().timestamp()))
